﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Entity;

namespace web.admin.Academy
{
    public partial class ACA_List : System.Web.UI.Page
    {
        AcademyService academyService = new AcademyService();
        LocalService localService = new LocalService();
        const int pagesize = 20;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                RP_Bind();
                localList.DataSource = localService.getAllLocal();
                localList.DataTextField = "LOC_NAME";
                localList.DataValueField = "LOC_ID";
                localList.DataBind();
                if (Session["LocalselectValue"] != null && Session["LocalselectValue"].ToString() != "")
                    localList.SelectedValue = Session["LocalselectValue"].ToString();
            }
        }
        /// <summary>
        /// reapeater控件绑定
        /// </summary>
        protected void RP_Bind()
        {
            Pager1.PageSize = pagesize;
            int records = 0;
            if (Session["LocalCon"] != null && Session["LocalCon"].ToString() != "")
            {
                Repeater1.DataSource = academyService.getPageCompetitions(Session["LocalCon"].ToString(), " ACA_NAME DESC", Pager1.PageSize, Pager1.PageIndex, out records);
            }
            else
                Repeater1.DataSource = academyService.getPageCompetitions("", " ACA_NAME DESC", Pager1.PageSize, Pager1.PageIndex, out records);
            Repeater1.DataBind();
            //初始化分页条,设置样式
            Pager1.SetPage(records);
            Pager1.ShowPageJump = true;
            Pager1.ShowPageLan = 0; //导航条语言:0=默认，1=中文，2=英语

        }
        //选择下拉列表更新
        protected void LocalList_SelectedIndexChanged(object sender, EventArgs e)
        {
            string selAcamediyId = localList.SelectedValue;
            if (selAcamediyId == "")
            {
                Session["LocalselectValue"] = "";
                Session["LocalCon"] = "";
            }
            else
            {
                Session["LocalselectValue"] = selAcamediyId;
                Session["LocalCon"] = "ACA_LOCAL='" + selAcamediyId + "'";
            }
            RP_Bind();
           
        }
        //批量删除
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int j = 0;
            for (int i = 0; i < Repeater1.Items.Count; i++)
            {
                string id =((HiddenField)Repeater1.Items[i].FindControl("Academy_Id")).Value;
                CheckBox cb = (CheckBox)Repeater1.Items[i].FindControl("CbChoose");
                if (cb.Checked)
                {
                    BoAcademy academ = academyService.getAcademy(id);
                    academyService.DeleteAcademy(academ);
                    j++;
                }
            }
            Response.Write("<script>alert('删除成功，共删除" + j + "条数据');window.location.href='ACA_List.aspx'; </script>");
            return;
        }
    }
}